﻿// Decompiled with JetBrains decompiler
// Type: MCM.Abstractions.SettingsPropertyDefinition
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using MCM.Abstractions.Attributes.v1;
using MCM.Abstractions.Wrapper;
using MCM.Common;
using System;
using System.Collections.Generic;

#nullable enable
namespace MCM.Abstractions
{
  public sealed class SettingsPropertyDefinition : 
    ISettingsPropertyDefinition,
    IPropertyDefinitionBase,
    IPropertyDefinitionBool,
    IPropertyDefinitionDropdown,
    IPropertyDefinitionWithMinMax,
    IPropertyDefinitionWithEditableMinMax,
    IPropertyDefinitionWithFormat,
    IPropertyDefinitionWithCustomFormatter,
    IPropertyDefinitionWithId,
    IPropertyDefinitionText,
    IPropertyDefinitionGroupToggle,
    IPropertyGroupDefinition,
    IPropertyDefinitionButton
  {
    public string Id { get; } = string.Empty;

    public IRef PropertyReference { get; }

    public SettingType SettingType { get; } = SettingType.NONE;

    public string DisplayName { get; } = string.Empty;

    public int Order { get; } = -1;

    public bool RequireRestart { get; } = true;

    public string HintText { get; } = string.Empty;

    public Decimal MaxValue { get; }

    public Decimal MinValue { get; }

    public Decimal EditableMinValue { get; }

    public Decimal EditableMaxValue { get; }

    public int SelectedIndex { get; }

    public string ValueFormat { get; } = string.Empty;

    public Type? CustomFormatter { get; }

    public string GroupName { get; }

    public bool IsToggle { get; }

    public int GroupOrder { get; }

    private char SubGroupDelimiter { get; }

    public string Content { get; } = string.Empty;

    public SettingsPropertyDefinition(
      IPropertyDefinitionBase propertyDefinition,
      IPropertyGroupDefinition propertyGroupDefinition,
      IRef propertyReference,
      char subGroupDelimiter)
      : this((IEnumerable<IPropertyDefinitionBase>) new IPropertyDefinitionBase[1]
      {
        propertyDefinition
      }, propertyGroupDefinition, propertyReference, subGroupDelimiter)
    {
    }

    public SettingsPropertyDefinition(
      IEnumerable<IPropertyDefinitionBase> propertyDefinitions,
      IPropertyGroupDefinition propertyGroupDefinition,
      IRef propertyReference,
      char subGroupDelimiter)
    {
      this.SubGroupDelimiter = subGroupDelimiter;
      string[] strArray = propertyGroupDefinition.GroupName.Split(this.SubGroupDelimiter);
      this.GroupName = string.Join(this.SubGroupDelimiter.ToString(), strArray);
      this.GroupOrder = propertyGroupDefinition.GroupOrder;
      this.PropertyReference = propertyReference;
      if (this.PropertyReference is PropertyRef propertyReference1)
        this.Id = propertyReference1.PropertyInfo.Name;
      if (this.PropertyReference.Type == typeof (bool))
        this.SettingType = SettingType.Bool;
      else if (this.PropertyReference.Type == typeof (int))
        this.SettingType = SettingType.Int;
      else if (this.PropertyReference.Type == typeof (float))
        this.SettingType = SettingType.Float;
      else if (this.PropertyReference.Type == typeof (string))
        this.SettingType = SettingType.String;
      else if (SettingsUtils.IsForGenericDropdown(this.PropertyReference.Type))
        this.SettingType = SettingType.Dropdown;
      else if (this.PropertyReference.Type == typeof (Action))
        this.SettingType = SettingType.Button;
      foreach (IPropertyDefinitionBase propertyDefinition in propertyDefinitions)
      {
        IPropertyDefinitionBase propertyDefinitionBase;
        int num;
        if (propertyDefinition != null)
        {
          propertyDefinitionBase = propertyDefinition;
          num = 1;
        }
        else
          num = 0;
        if (num != 0)
        {
          this.DisplayName = propertyDefinitionBase.DisplayName;
          this.Order = propertyDefinitionBase.Order;
          this.RequireRestart = propertyDefinitionBase.RequireRestart;
          this.HintText = propertyDefinitionBase.HintText;
        }
        if (propertyDefinition is SettingPropertyAttribute propertyAttribute)
        {
          this.MinValue = propertyAttribute.MinValue;
          this.MaxValue = propertyAttribute.MaxValue;
          this.EditableMinValue = propertyAttribute.MinValue;
          this.EditableMaxValue = propertyAttribute.MaxValue;
        }
        if (!(propertyDefinition is IPropertyDefinitionBool))
          ;
        if (propertyDefinition is IPropertyDefinitionWithMinMax definitionWithMinMax)
        {
          this.MinValue = definitionWithMinMax.MinValue;
          this.MaxValue = definitionWithMinMax.MaxValue;
          this.EditableMinValue = definitionWithMinMax.MinValue;
          this.EditableMaxValue = definitionWithMinMax.MaxValue;
        }
        if (propertyDefinition is IPropertyDefinitionWithEditableMinMax withEditableMinMax)
        {
          this.EditableMinValue = withEditableMinMax.EditableMinValue;
          this.EditableMaxValue = withEditableMinMax.EditableMaxValue;
        }
        if (propertyDefinition is IPropertyDefinitionWithFormat definitionWithFormat)
          this.ValueFormat = definitionWithFormat.ValueFormat;
        if (propertyDefinition is IPropertyDefinitionWithCustomFormatter withCustomFormatter)
          this.CustomFormatter = withCustomFormatter.CustomFormatter;
        if (!(propertyDefinition is IPropertyDefinitionWithActionFormat))
          ;
        if (!(propertyDefinition is IPropertyDefinitionText))
          ;
        if (propertyDefinition is IPropertyDefinitionDropdown definitionDropdown)
          this.SelectedIndex = definitionDropdown.SelectedIndex;
        if (propertyDefinition is IPropertyDefinitionWithId definitionWithId)
          this.Id = definitionWithId.Id;
        if (propertyDefinition is IPropertyDefinitionGroupToggle definitionGroupToggle)
          this.IsToggle = definitionGroupToggle.IsToggle;
        if (propertyDefinition is IPropertyDefinitionButton definitionButton)
          this.Content = definitionButton.Content;
      }
    }

    public override string ToString() => "[" + this.GroupName + "]: " + this.DisplayName;

    public SettingsPropertyDefinition Clone(bool keepRefs = true)
    {
      object obj = this.PropertyReference.Value;
      IRef propertyReference = keepRefs ? this.PropertyReference : (IRef) new StorageRef(obj is ICloneable cloneable ? cloneable.Clone() : obj);
      return new SettingsPropertyDefinition(SettingsUtils.GetPropertyDefinitionWrappers((object) this), (IPropertyGroupDefinition) new PropertyGroupDefinitionWrapper((object) this), propertyReference, this.SubGroupDelimiter);
    }
  }
}
